<?php
/**
 * @abstract 进行建行支付
 * @author ran.ran
 * @example
 * public function actions()
    {
        return [
            'ccbpay'=>
            [
                'class'=>'components\AlipayAction',
                'notifyUrl'=>'http://www.baidu.com'
            ]

        ];
    }
 */

namespace components;

use ccb\ccbpay\Ccbalipay;
use yii\base\Exception;
use Yii;
use yii\web\NotFoundHttpException;

class CcbPayAction extends BasePayMentAction
{
    /**
     * 备注1
     * @var string
     */
    public  $REMARK1 = '';
    
    /**
     * 备注2
     * @var string
     */
    public  $REMARK2 = '';
    
    /**
     * 商户域名
     * @var string
     */
    public $MER_REFERER='';
    
    /**
     * 银行接口地址
     * @var string
     */
    private  $bankURL = 'https://ibsbjstar.ccb.com.cn/app/ccbMain';
    /**
     * 网关类型
     * @var string
     */
    private  $GATEWAY = '';
    /**
     * 客户端ip
     * @var string
     */
    public $CLIENTIP= 'http://127.0.0.1';//TODO上线自动获取；$_SERVER['REMOTE_ADDR']
    
    public $MAC= '';
    
    public $URL01 = '';
    
    public $REM1 = '';

    public $REM2 ='';
    
    public $result = '';
    
    private $config = [];
    
    public $mode = 'ccb';
    
    public function run(){
       try{
           //验证
           $res = $this->validateOrderInfo();
            
           //用户已经支付及支付金额小于0 。跳转到详情页
           if(!$res['flag']) {
               $url = Yii::$app->urlManager->createUrl(['order-details/order-list']);
               return Yii::$app->response->redirect($url);
           }
           
           $this->config['ORDERID'] = $this->payment->order_sn;
           $this->config['PAYMENT'] = $this->payment->order_amount;
           $this->config['REMARK1'] = $this->REMARK1;
           $this->config['REMARK2'] = $this->REMARK2;
           $this->config['GATEWAY'] = $this->GATEWAY;
           $this->config['CLIENTIP'] = $this->CLIENTIP;
           $this->config['REGINFO'] = $this->body;
           $this->config['PROINFO'] = $this->subject;
           $this->config['MER_REFERER'] = $this->MER_REFERER;
           $this->config['bankURL'] = $this->bankURL;
           $this->config['result'] = $this->result;
           $this->config['MAC'] = $this->MAC;
           $this->config['URL01'] = $this->URL01;
           $this->config['REM1'] = $this->REM1;
           $this->config['REM2'] = $this->REM2;
            
            
           $ccb = new Ccbalipay($this->config);
           
           return $ccb->buildRequestForm();
            
       } catch(Exception $e){
       
           throw  new NotFoundHttpException();
       }
       
    }
    
}

?>